package com.ly.dingtalk.service.role.impl;

import com.dingtalk.api.request.OapiRoleAddRoleRequest;
import com.dingtalk.api.request.OapiRoleAddrolegroupRequest;
import com.dingtalk.api.request.OapiRoleAddrolesforempsRequest;
import com.dingtalk.api.request.OapiRoleDeleteroleRequest;
import com.dingtalk.api.request.OapiRoleGetroleRequest;
import com.dingtalk.api.request.OapiRoleGetrolegroupRequest;
import com.dingtalk.api.request.OapiRoleListRequest;
import com.dingtalk.api.request.OapiRoleRemoverolesforempsRequest;
import com.dingtalk.api.request.OapiRoleScopeUpdateRequest;
import com.dingtalk.api.request.OapiRoleSimplelistRequest;
import com.dingtalk.api.request.OapiRoleUpdateRoleRequest;
import com.dingtalk.api.response.OapiRoleAddRoleResponse;
import com.dingtalk.api.response.OapiRoleAddrolegroupResponse;
import com.dingtalk.api.response.OapiRoleAddrolesforempsResponse;
import com.dingtalk.api.response.OapiRoleDeleteroleResponse;
import com.dingtalk.api.response.OapiRoleGetroleResponse;
import com.dingtalk.api.response.OapiRoleGetrolegroupResponse;
import com.dingtalk.api.response.OapiRoleListResponse;
import com.dingtalk.api.response.OapiRoleRemoverolesforempsResponse;
import com.dingtalk.api.response.OapiRoleScopeUpdateResponse;
import com.dingtalk.api.response.OapiRoleSimplelistResponse;
import com.dingtalk.api.response.OapiRoleUpdateRoleResponse;
import com.ly.dingtalk.component.application.IDingApp;
import com.ly.dingtalk.constant.DingUrlConstant;
import com.ly.dingtalk.service.AbstractDingNewApi;
import com.ly.dingtalk.service.role.IDingRoleHandler;

public class DingRoleNewHandler extends AbstractDingNewApi implements IDingRoleHandler{

    public DingRoleNewHandler(IDingApp app) {
        super(app);
    }

    /**
     * @Description:  https://oa.dingtalk.com/contacts.htm#/contacts?role  新增的角色可以在企业管理后台查看
     * @see com.ly.dingtalk.service.role.IDingRoleHandler#addRole(com.dingtalk.api.request.OapiRoleAddRoleRequest)
     */
    @Override
    public OapiRoleAddRoleResponse addRole(OapiRoleAddRoleRequest req) {
        return execute(
                DingUrlConstant.Role.ADD_ROLE,
                req,
                () -> "新增角色"
        );
    }
    
    /**
     * 
     * @Description: TODO 增加的角色组可以在 https://oa.dingtalk.com/contacts.htm#/contacts?role 这里查看
     * @see com.ly.dingtalk.service.role.IDingRoleHandler#addRoleGroup(com.dingtalk.api.request.OapiRoleAddrolegroupRequest)
     */
    @Override
    public OapiRoleAddrolegroupResponse addRoleGroup(OapiRoleAddrolegroupRequest req) {
        return execute(
                DingUrlConstant.Role.ADD_ROLE_GROUP,
                req,
                () -> "新增角色组"
        );
    }
    
    @Override
    public OapiRoleUpdateRoleResponse updateRole(OapiRoleUpdateRoleRequest req) {
        return execute(
                DingUrlConstant.Role.UPDATE_ROLE,
                req,
                () -> "更新角色"
        );
    }
    
    /**
     * 
     * @Description: TODO
     * @see com.ly.dingtalk.service.role.IDingRoleHandler#addrolesforemps(com.dingtalk.api.request.OapiRoleAddrolesforempsRequest)
     */
    @Override
    public OapiRoleAddrolesforempsResponse addrolesforemps(OapiRoleAddrolesforempsRequest req) {
        return execute(
                DingUrlConstant.Role.ADD_ROLESFOREMPS,
                req,
                () -> "批量增加员工角色"
        );
    }
    
    
    @Override
    public OapiRoleDeleteroleResponse deleterole(Long roleId) {
        OapiRoleDeleteroleRequest req = new OapiRoleDeleteroleRequest();
        req.setRoleId(roleId);
        return execute(
                DingUrlConstant.Role.DELETE_ROLE,
                req,
                () -> "删除角色"
        );
    }
    
    @Override
    public OapiRoleRemoverolesforempsResponse removerolesforemps(OapiRoleRemoverolesforempsRequest req) {
        return execute(
                DingUrlConstant.Role.REMOVE_ROLESFOREMPS,
                req,
                () -> "批量删除员工角色"
        );
    }
    
    @Override
    public OapiRoleScopeUpdateResponse update(OapiRoleScopeUpdateRequest req) {
        return execute(
                DingUrlConstant.Role.UPDATE,
                req,
                () -> "设定角色成员管理范围"
        );
    }
    
    @Override
    public OapiRoleGetrolegroupResponse getrolegroup(Long groupId) {
        OapiRoleGetrolegroupRequest req = new OapiRoleGetrolegroupRequest();
        req.setGroupId(groupId);
        return execute(
                DingUrlConstant.Role.GET_ROLE_GROUP,
                req,
                () -> "获取角色组"
        );
    }
    
    @Override
    public OapiRoleListResponse roleList(OapiRoleListRequest req) {
        return execute(
                DingUrlConstant.Role.ROLE_LIST,
                req,
                () -> "获取角色列表"
        );
    }
    
    @Override
    public OapiRoleGetroleResponse getrole(Long roleId) {
        OapiRoleGetroleRequest req = new OapiRoleGetroleRequest();
        req.setRoleId(roleId);
        return execute(
                DingUrlConstant.Role.GET_ROLE,
                req,
                () -> "获取角色详情"
        );
    }
    
    @Override
    public OapiRoleSimplelistResponse simplelist(OapiRoleSimplelistRequest req) {
        return execute(
                DingUrlConstant.Role.SIMPLE_LIST,
                req,
                () -> "获取指定角色的员工列表"
        );
    }

}
